package vip.george.proxybeantest.controller;


import org.springframework.aop.support.AopUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import vip.george.proxybeantest.config.MyConfig;
import vip.george.proxybeantest.service.AsyncService;
import vip.george.proxybeantest.service.MyService;
import vip.george.proxybeantest.service.impl.NotParentAsyncService;

import java.lang.reflect.Proxy;


@EnableAsync
@RestController
@RequestMapping("/demo")
public class DemoController {


    @Autowired
    private MyService myService;

    @Autowired
    private NotParentAsyncService notParentAsyncService;

    @Autowired
    private AsyncService asyncService;

    @Autowired
    private MyConfig myConfig;

    @RequestMapping("/hello")
    public String hello() {
        System.out.println("========myService:===========");
        System.out.println(myService);
        System.out.println("myService 是否是cglib代理? " + AopUtils.isCglibProxy(myService));
        System.out.println("myService 是否是jdk代理? " + Proxy.isProxyClass(myService.getClass() ));



        System.out.println("========asyncService:===========");
        System.out.println(asyncService);
        System.out.println("asyncService 是否是cglib代理? " + AopUtils.isCglibProxy(asyncService));
        System.out.println("asyncService 是否是jdk代理? " + Proxy.isProxyClass(asyncService.getClass()));


        System.out.println("========notParentAsyncService:==========");
        System.out.println(notParentAsyncService);
        System.out.println("notParentService 是否是cglib代理? " + AopUtils.isCglibProxy(notParentAsyncService));
        System.out.println("notParentService 是否是jdk代理? " + Proxy.isProxyClass(notParentAsyncService.getClass() ));
        
        System.out.println("========myConfig============");
        System.out.println(myConfig);
        System.out.println("myConfig 是否是cglib代理? " + AopUtils.isCglibProxy(myConfig));
        System.out.println("myConfig 是否是jdk代理? " + Proxy.isProxyClass(myConfig.getClass()));
        asyncService.doInTransaction();

        return "end end ...........";
    }
}
